<?php
class Bank extends CI_Controller{
         private $limit = 10;
	function  __construct() {
        parent::__construct();
        $this->load->model('Bank_model');
		$this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $this->load->library(array('form_validation','pagination'));
  
      }
     
	function index($offset=''){
      
		$this->load->library('pagination'); 
		$uri_segment = 3;
		$offset = $this->uri->segment($uri_segment);
		
		$config['base_url'] = site_url('bank/index/');
		$config['total_rows'] = $this->Bank_model->countData();
		$config['per_page'] = $this->limit;
		$config['num_links'] = 2;
		$config['full_tag_open'] = '<div id="pagination">';
		$config['full_tag_close'] = '</div>';
		
		$this->pagination->initialize($config);
		$data['pagination'] = $this->pagination->create_links();
		$data['offset']=$offset;
		$data['jumlah_data']=$this->Bank_model->countData();
		
		$data['bank']	= $this->Bank_model->get_list_data($this->limit,$offset)->result();
	

       $this->load->view('admin_views/bank/bank', $data);
    }
  
	function add()
	{
		$this->form_validation->set_rules('strnama_bank', 'Nama Bank', 'trim|required|xss_clean');

		$this->form_validation->set_message('required', ' %s tidak boleh kosong !!');

		if ($this->form_validation->run() == FALSE)
		 {
                       $this->load->view('admin_views/bank/add');
		}else{

                        $this->Bank_model->insert($_POST);
			redirect('bank/bank');
                }
	}

      function edit($intid_bank)
		{
			if($_POST==NULL)
			{

				$datauser= $this->Bank_model->select($intid_bank);
				foreach ($datauser as $g)
				{
					$data['intid_bank']	 	= $g->intid_bank;
					$data['strnama_bank'] 		= $g->strnama_bank;
				}
				$this->load->view('admin_views/bank/edit', $data);
			}else {
				$this->Bank_model->update($intid_bank);
				redirect('bank/index');
			}

		}
	

    function delete($intid_bank)
	{
		$this->Bank_model->delete($intid_bank);
		redirect('bank/bank');
	}


}
?>
